package com.wiim.adapter;

import java.util.ArrayList;

import com.wiim.common.ConstantValue;
import com.wiim.connector.RestClient;
import com.wiim.model.ExchangeAwardData;
import com.wiim.model.ShopData;
import com.wiim.model.TransactionLogData;
import com.wiim.nhapnhap.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LichsuAdapter extends BaseAdapter {
	// private ArrayList<ExchangeAwardData> listData;
	private ArrayList<TransactionLogData> listData;
	private Activity ac;
	private boolean isCredit;

	// private String service_url = "common/getfilestream/";

	static class ViewHolder {
		TextView tvName;
		TextView tvPoint;
	}

	public LichsuAdapter(final Activity _ac, ArrayList<TransactionLogData> _list,Boolean _isCredit) {
		this.listData = _list;
		this.ac = _ac;
		this.isCredit=_isCredit;
		// imageLoader = new ImageLoader(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return listData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(ac);
			convertView = inflater.inflate(R.layout.item_lichsu_layout, null);
			holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
			holder.tvPoint = (TextView) convertView.findViewById(R.id.tvPoint);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tvName.setText(listData.get(position).PartnerName);
		// holder.imgPics.setBackgroundResource(listData.get(position).ShopName);
		if(isCredit){
			holder.tvPoint.setText("+ "+listData.get(position).Debit+" point");
		}else{
			holder.tvPoint.setText("+ "+listData.get(position).Credit+" point");
		}
//		notifyDataSetChanged();
		

//		convertView.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				((CustomFragmentActivity) ac).setPassValue("SHOPID", listData.get(position).ShopID);
//				((CustomFragmentActivity) ac).replaceFragment(ConstantValue.STORE_DETAIL_FRAGMENT, false);
//			}
//		});

		// ((CustomFragmentActivity)ac).imageLoader2.displayImage(RestClient.apiUrl(service_url
		// + listData.get(position).ShopID), holder.imgPics,
		// ((CustomFragmentActivity) ac).options);

		return convertView;
	}

}
